//
//  Helper.h
//  SkyFight
//
//  Created by HoangLinh on 7/25/13.
//
//

#ifndef __SkyFight__Helper__
#define __SkyFight__Helper__

#include <iostream>
#include <string>
#include <mutex>

#include "pugixml.hpp"

#include "cocos2d.h"
#include "Box2D.h"

using namespace std;
using namespace pugi;
USING_NS_CC;

// debug
#define CCOBJECT_DEBUG 1

// --------------- box2d ----------
#define MAX_VERTICES 8
#define GRAVITY -9.8f
#define PTM_RATIO 32.0f

#define DEATHLINE 32.f


// data key-----------------------
#define KEY_OBJECTS     "objects"
#define KEY_NAME        "name"
#define KEY_FIXTURES    "fixtures"
#define KEY_ATTRIBUTES  "attributes"
#define KEY_VERTICES    "vertices"
#define KEY_SHAPE       "shape"
#define KEY_TYPE        "type"
#define KEY_POLYGON     "polygon"
#define KEY_CIRCLE      "circle"
#define KEY_POSITION    "position"
#define KEY_X           "x"
#define KEY_Y           "y"
#define KEY_RADIUS      "radius"
#define KEY_FRICTION    "friction"
#define KEY_RESTITUTION "restitution"
#define KEY_DENSITY     "density"
#define KEY_SENSOR      "sensor"
#define KEY_LAND        "land"
#define KEY_CLOUD       "cloud"
#define KEY_SPIKE       "spike"
#define KEY_ITEM        "item"
#define KEY_HERO        "hero"
#define KEY_ENEMY       "enemy"
#define KEY_LANDBODY    "landbody"
#define KEY_USERDATA    "userData"
#define KEY_PROPERTIES  "properties"
#define TILE_ID         "gid"

#define DEFAULT_LIFENUMBER 3

// enum --------------------------
typedef enum
{
    DIRECT_NONE,
    DIRECT_UP,
    DIRECT_DOWN,
    DIRECT_LEFT,
    DIRECT_RIGHT
} GAME_DIRECTION;

typedef enum
{
    LAND,
    CLOUD,
    WATER,
    SPIKE,
    LEVER,
    MONSTER,
    ITEM,
    BUBBLE,
    BALLOON,
    STONE,
    ARROW,
    JAVELIN,
    ENEMY,
    HERO
} GAME_OBJECT;

typedef enum
{
    GAME_STATE_RUNNING,
    GAME_STATE_PAUSE
} GAME_STATE;

typedef enum
{
    CONTROL_TOUCH,
    CONTROL_LEFTJOYSTICK
} GAME_CONTROL;

typedef enum
{
    WP_STONE = 0,
    WP_ARROW = 1,
    WP_JAVELIN = 2
} WEAPON;

#define ITEM_NUM 4
typedef enum {
    IT_POINT = 0,
    IT_STONE = 1,
    IT_BOW = 2,
    IT_JAVELIN = 3
} GAME_ITEM;

// functions -----------------------------------------------------------
CCDictionary* getAttributeDict(const xml_node *xmlNode);
CCDictionary* getAttributeDict(const xml_node_iterator xmlNode);
CCPoint getPosFromDict(CCDictionary *_dict, CCSize _objSize);
CCSize getSizeFromDict(CCDictionary *_dict);
b2Vec2 getPosFromDict(CCDictionary *_dict);
float getRadiusFromDict(CCDictionary *_dict);

float lengthOfVector(b2Vec2 vect);

int randomFromTo(int _from, int _to);
float frandomFromTo(float _from, float _to, int _fraction);
b2Vec2 getVectorDirection(float x, float y);

#endif /* defined(__SkyFight__Helper__) */
